package com.epalmpay.controller.channel.ys.obd;

import com.epalmpay.commom.BaseController;
import com.epalmpay.entity.YsObd;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.agent.AgentListOutDTO;
import com.epalmpay.dto.system.BaseOutDTO;
import com.epalmpay.dto.yunliu.obd.*;
import com.epalmpay.dto.yunliu.profit.ObdProfitRuleListOutDTO;
import com.epalmpay.dto.yunliu.profit.ObdProfitRuleOutDTO;
import com.epalmpay.entity.YsObdProfitRule;
import com.epalmpay.entity.YsObdPurchaseApply;
import com.epalmpay.entity.YsObdPurchaseSet;
import com.epalmpay.enumdef.CommonEnum;
import com.epalmpay.enumdef.YunStreamEnum;
import com.epalmpay.service.operator.ISysLogService;
import com.epalmpay.service.yunstream.IObdProfitRule;
import com.epalmpay.service.yunstream.IObdService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value="/merchant/ys/obd")
public class ObdController extends BaseController {
     
	@Resource
	private IObdService obdService;
	@Resource
    private IObdProfitRule ObdProfitRuleService;

	@Resource
	private ISysLogService sysLogService;
	
	@RequestMapping(value="/storeList")
	@ResponseBody
	public ObdStoreListOutDTO  redpackageList(@RequestBody ObdInDTO obdInDTO){
		ObdStoreListOutDTO obdStoreListOutDTO=new ObdStoreListOutDTO();
		try {
			obdStoreListOutDTO = obdService.getStoreList(obdInDTO);
			obdStoreListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdStoreListOutDTO;
		} catch (ApplicationException ae) {
			obdStoreListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdStoreListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdStoreListOutDTO;
	}

	@RequestMapping(value="/delObd")
	@ResponseBody
	public BaseOutDTO delObd(@RequestBody ObdInDTO obdInDTO){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			int result = obdService.deleteObd(obdInDTO);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return baseOutDTO;
	}

	@RequestMapping(value="/batchdelete")
	@ResponseBody
	public BaseOutDTO batchdelete(@RequestBody ObdAddInDTO obdAddInDTO){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			int result = obdService.deleteObdForBatch(obdAddInDTO);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return baseOutDTO;
	}

	@RequestMapping(value="/storebatchList")
	@ResponseBody
	public ObdStoreListOutDTO  storebatchList(@RequestBody ObdInDTO obdInDTO){
		ObdStoreListOutDTO obdStoreListOutDTO=new ObdStoreListOutDTO();
		try {
			obdStoreListOutDTO = obdService.getStoreBatchList(obdInDTO);
			obdStoreListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdStoreListOutDTO;
		} catch (ApplicationException ae) {
			obdStoreListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdStoreListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdStoreListOutDTO;
	}

	@RequestMapping(value="/storebatchItemList")
	@ResponseBody
	public ObdStoreListOutDTO  storebatchItemList(@RequestBody ObdInDTO obdInDTO){
		ObdStoreListOutDTO obdStoreListOutDTO=new ObdStoreListOutDTO();
		try {
			obdStoreListOutDTO = obdService.getStoreBatchItemList(obdInDTO);
			obdStoreListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdStoreListOutDTO;
		} catch (ApplicationException ae) {
			obdStoreListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdStoreListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdStoreListOutDTO;
	}

	@RequestMapping(value="/distributionList")
	@ResponseBody
	public ObdDistributionListOutDTO  distributionList(@RequestBody ObdInDTO obdInDTO){
		ObdDistributionListOutDTO obdDistributionListOutDTO = new ObdDistributionListOutDTO();
		try {
			obdDistributionListOutDTO = obdService.getDistributionList(obdInDTO);
			obdDistributionListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdDistributionListOutDTO;
		} catch (ApplicationException ae) {
			obdDistributionListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdDistributionListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdDistributionListOutDTO;
	}

	@RequestMapping(value="/delObdDistribution")
	@ResponseBody
	public BaseOutDTO delObdDistribution(@RequestBody ObdInDTO obdInDTO){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			int result = obdService.deleteObdDistribution(obdInDTO);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return baseOutDTO;
	}

	@RequestMapping(value="/batchrecall")
	@ResponseBody
	public BaseOutDTO batchrecall(@RequestBody ObdAddInDTO obdAddInDTO){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			int result = obdService.deleteDistributeForBatch(obdAddInDTO);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return baseOutDTO;
	}


	@RequestMapping(value="/distributionbatchList")
	@ResponseBody
	public ObdDistributionListOutDTO  distributionbatchList(@RequestBody ObdInDTO obdInDTO){
		ObdDistributionListOutDTO obdDistributionListOutDTO=new ObdDistributionListOutDTO();
		try {
			obdDistributionListOutDTO = obdService.getDistributionBatchList(obdInDTO);
			obdDistributionListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdDistributionListOutDTO;
		} catch (ApplicationException ae) {
			obdDistributionListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdDistributionListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdDistributionListOutDTO;
	}

	@RequestMapping(value="/distributionbatchItemList")
	@ResponseBody
	public ObdDistributionListOutDTO  distributionbatchItemList(@RequestBody ObdInDTO obdInDTO){
		ObdDistributionListOutDTO obdDistributionListOutDTO=new ObdDistributionListOutDTO();
		try {
			obdDistributionListOutDTO = obdService.getDistributionBatchItemList(obdInDTO);
			obdDistributionListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdDistributionListOutDTO;
		} catch (ApplicationException ae) {
			obdDistributionListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdDistributionListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdDistributionListOutDTO;
	}

	@RequestMapping(value="/obdDetail")
	@ResponseBody
	public ObdDetailOutDTO  obdDetail(@RequestBody ObdInDTO obdInDTO){
		ObdDetailOutDTO obdDetailOutDTO = new ObdDetailOutDTO();
		try {
			obdDetailOutDTO = obdService.getObdDetail(obdInDTO);
			if(obdDetailOutDTO == null)
				obdDetailOutDTO = new ObdDetailOutDTO();
			obdDetailOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdDetailOutDTO;
		} catch (ApplicationException ae) {
			obdDetailOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdDetailOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdDetailOutDTO;
	}

	@RequestMapping(value="/toObdStoreAdd")
	@ResponseBody
	public ObdOutDTO toObdStoreAdd(@RequestBody ObdAddInDTO obdAddInDTO){
		ObdOutDTO obdOutDTO = new ObdOutDTO();
		try {
			obdOutDTO = obdService.toObdStoreAdd(obdAddInDTO);
			obdOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdOutDTO;
		} catch (ApplicationException ae) {
			obdOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdOutDTO;
	}

	@RequestMapping(value="/storeAdd")
	@ResponseBody
	public ObdOutDTO storeAdd(@RequestBody ObdAddInDTO obdAddInDTO){
		ObdOutDTO baseOutDTO=new ObdOutDTO();
		try {
			int result = obdService.addStore(obdAddInDTO);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return baseOutDTO;
	}

	@RequestMapping(value="/devicedistribution")
	@ResponseBody
	public BaseOutDTO devicedistribution(@RequestBody ObdAddInDTO obdAddInDTO){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			int result = obdService.addDeviceDistribution(obdAddInDTO);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return baseOutDTO;
	}

	@RequestMapping(value="/shopOBDList")
	@ResponseBody
	public ObdShopListOutDTO  shopOBDList(@RequestBody ObdInDTO obdInDTO){
		ObdShopListOutDTO obdShopListOutDTO=new ObdShopListOutDTO();
		try {
			obdShopListOutDTO = obdService.getShopOBDList(obdInDTO);
			obdShopListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdShopListOutDTO;
		} catch (ApplicationException ae) {
			obdShopListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdShopListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdShopListOutDTO;
	}

	@RequestMapping(value="/agentOBDList")
	@ResponseBody
	public ObdAgentListOutDTO  agentOBDList(@RequestBody ObdInDTO obdInDTO){
		ObdAgentListOutDTO obdAgentListOutDTO=new ObdAgentListOutDTO();
		try {
			obdAgentListOutDTO = obdService.getAgentOBDList(obdInDTO);
			obdAgentListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdAgentListOutDTO;
		} catch (ApplicationException ae) {
			obdAgentListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdAgentListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdAgentListOutDTO;
	}

	@RequestMapping(value="/profit/ysObdProfitRuleList")
	@ResponseBody
	public ObdProfitRuleListOutDTO ysObdProfitRuleList(@RequestBody YsObdProfitRule YsObdProfitRule){
		ObdProfitRuleListOutDTO ObdProfitRuleListOutDTO =new ObdProfitRuleListOutDTO();
		try {
			ObdProfitRuleListOutDTO = ObdProfitRuleService.ysObdProfitRuleList(YsObdProfitRule);
			ObdProfitRuleListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return ObdProfitRuleListOutDTO;
		} catch (ApplicationException ae) {
			ObdProfitRuleListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			ObdProfitRuleListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return ObdProfitRuleListOutDTO;
	}

	@RequestMapping(value="/profit/SetObdProfitRule")
	@ResponseBody
	public ObdProfitRuleOutDTO SetObdProfitRule(@RequestBody YsObdProfitRule YsObdProfitRule){
		ObdProfitRuleOutDTO ObdProfitRuleOutDTO =new ObdProfitRuleOutDTO();
		try {
			ObdProfitRuleOutDTO = ObdProfitRuleService.SetysObdProfitRule(YsObdProfitRule);
			ObdProfitRuleOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return ObdProfitRuleOutDTO;
		} catch (ApplicationException ae) {
			ObdProfitRuleOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			ObdProfitRuleOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return ObdProfitRuleOutDTO;
	}


	@RequestMapping(value="/profit/deleteObdProfitRule")
	@ResponseBody
	public ObdProfitRuleOutDTO DeleteObdProfitRule(@RequestBody YsObdProfitRule YsObdProfitRule){
		ObdProfitRuleOutDTO ObdProfitRuleOutDTO =new ObdProfitRuleOutDTO();
		try {
			ObdProfitRuleOutDTO = ObdProfitRuleService.DeleteObdProfitRule(YsObdProfitRule);
			ObdProfitRuleOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return ObdProfitRuleOutDTO;
		} catch (ApplicationException ae) {
			ObdProfitRuleOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			ObdProfitRuleOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return ObdProfitRuleOutDTO;
	}

	@RequestMapping(value="/profit/getAgentWithLevelFirst")
	@ResponseBody
	public AgentListOutDTO etAgentWithLevelFirst(@RequestBody YsObdProfitRule ysObdProfitRule){
		AgentListOutDTO agentListOutDTO=new AgentListOutDTO();
		try {
			agentListOutDTO = ObdProfitRuleService.agentList(ysObdProfitRule.getGroupId(), ysObdProfitRule.getPage(),ysObdProfitRule.getOtherType());
			agentListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return agentListOutDTO;
		}
		catch (Exception e) {
			agentListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return agentListOutDTO;
	}

	@RequestMapping(value="/purchaseApplyList")
	@ResponseBody
	public ObdPurchaseApplyListOutDTO  purchaseApplayList(@RequestBody ObdInDTO obdInDTO){
		ObdPurchaseApplyListOutDTO obdPurchaseApplyListOutDTO=new ObdPurchaseApplyListOutDTO();
		try {
			obdPurchaseApplyListOutDTO = obdService.getPurchaseApplayList(obdInDTO);
			obdPurchaseApplyListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdPurchaseApplyListOutDTO;
		} catch (ApplicationException ae) {
			obdPurchaseApplyListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdPurchaseApplyListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdPurchaseApplyListOutDTO;
	}

	@RequestMapping(value="/OpertorApplyList")
	@ResponseBody
	public ObdApplyStepListOutDTO  OpertorApplyList(@RequestBody ObdInDTO obdInDTO){
		ObdApplyStepListOutDTO obdApplyStepListOutDTO=new ObdApplyStepListOutDTO();
		try {
			obdApplyStepListOutDTO = obdService.getOpertorApplayList(obdInDTO);
			obdApplyStepListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdApplyStepListOutDTO;
		} catch (ApplicationException ae) {
			obdApplyStepListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdApplyStepListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdApplyStepListOutDTO;
	}



	@RequestMapping(value="/obdApplayDetail")
	@ResponseBody
	public ObdPurchaseApplyOutDTO  obdApplayDetail(@RequestBody Long id){
		ObdPurchaseApplyOutDTO obdPurchaseApplyOutDTO=new ObdPurchaseApplyOutDTO();
		try {
			obdPurchaseApplyOutDTO = obdService.getObdApplayInfo(id);
			obdPurchaseApplyOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdPurchaseApplyOutDTO;
		} catch (ApplicationException ae) {
			obdPurchaseApplyOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdPurchaseApplyOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdPurchaseApplyOutDTO;
	}

	@RequestMapping(value="/obdSmQr")
	@ResponseBody
	public ObdSmOutDTO  doApplaySingleAmount(@RequestBody ObdSmOutDTO obdSmOutDTO){
		ObdSmOutDTO result =new ObdSmOutDTO();
		try {
			obdSmOutDTO.setQrUrl(HOME_URL+"/api/pay/obdIndex");
			result = obdService.getObdSmUrl(obdSmOutDTO);
			if (result == null){
				result = new ObdSmOutDTO();
			}
			result.setErrorCode(Rescode.SUCCESS, "处理成功");
			return result;
		} catch (ApplicationException ae) {
			result.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			result.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return result;
	}



	@RequestMapping(value="/doApplaySingleAmount")
	@ResponseBody
	public ObdPurchaseApplyOutDTO  doApplaySingleAmount(@RequestBody ObdInDTO obdInDTO){
		ObdPurchaseApplyOutDTO obdPurchaseApplyOutDTO=new ObdPurchaseApplyOutDTO();
		try {
			obdPurchaseApplyOutDTO = obdService.getObdSigleAmount(obdInDTO);
			if (obdPurchaseApplyOutDTO == null){
				obdPurchaseApplyOutDTO = new ObdPurchaseApplyOutDTO();
			}
			obdPurchaseApplyOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdPurchaseApplyOutDTO;
		} catch (ApplicationException ae) {
			obdPurchaseApplyOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdPurchaseApplyOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdPurchaseApplyOutDTO;
	}


	@RequestMapping(value="/editApplayNumAndAmount")
	@ResponseBody
	public ObdPurchaseApplyOutDTO editApplayNumAndAmount(@RequestBody ObdInDTO obdInDTO){

		ObdPurchaseApplyOutDTO obdPurchaseApplyOutDTO=new ObdPurchaseApplyOutDTO();
		try {
			obdPurchaseApplyOutDTO = obdService.getObdNumAndSigleAmount(obdInDTO);
			if (obdPurchaseApplyOutDTO == null){
				obdPurchaseApplyOutDTO = new ObdPurchaseApplyOutDTO();
			}
			obdPurchaseApplyOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdPurchaseApplyOutDTO;
		} catch (ApplicationException ae) {
			obdPurchaseApplyOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdPurchaseApplyOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdPurchaseApplyOutDTO;
	}



	/**
	 * 更新申请采购数量和金额
	 *
	 * @return
	 */
	@RequestMapping(value = "/updateNumAndAmount")
	@ResponseBody
	public BaseOutDTO updateNumAndAmount(@RequestBody YsObdPurchaseApply data) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		int i = obdService.updateNumAndAmountApply(data);
		if (i > 0) {
			baseOutDTO.setErrorCode(Rescode.SUCCESS);
		} else {
			baseOutDTO.setErrorCode(Rescode.FAIL);
		}
		return baseOutDTO;
	}

	/**
	 * 确定申请采购
	 *
	 * @return
	 */
	@RequestMapping(value = "/updatePayType")
	@ResponseBody
	public BaseOutDTO updatePayType(@RequestBody YsObdPurchaseApply data) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		int i = obdService.updatePayType(data);
		if (i > 0) {
			baseOutDTO.setErrorCode(Rescode.SUCCESS);
		} else {
			baseOutDTO.setErrorCode(Rescode.FAIL);
		}
		return baseOutDTO;
	}

	/**
	 * 确定申请采购
	 *
	 * @return
	 */
	@RequestMapping(value = "/uploadRemitCommit")
	@ResponseBody
	public BaseOutDTO uploadRemitCommit(@RequestBody YsObdPurchaseApply data) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		int i = obdService.updateRemitCommit(data);
		if (i > 0) {
			baseOutDTO.setErrorCode(Rescode.SUCCESS);
		} else {
			baseOutDTO.setErrorCode(Rescode.FAIL);
		}
		return baseOutDTO;
	}

	/**
	 * 确定收款提交
	 *
	 * @return
	 */
	@RequestMapping(value = "/confirmPayCommit")
	@ResponseBody
	public BaseOutDTO confirmPayCommit(@RequestBody YsObdPurchaseApply data) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		int i = obdService.confirmPayCommit(data);
		if (i > 0) {
			baseOutDTO.setErrorCode(Rescode.SUCCESS);
		} else {
			baseOutDTO.setErrorCode(Rescode.FAIL);
		}
		return baseOutDTO;
	}

	/**
	 * 确定申请采购
	 *
	 * @return
	 */
	@RequestMapping(value = "/doApplay")
	@ResponseBody
	public BaseOutDTO doApplay(@RequestBody YsObdPurchaseApply data) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		int i = obdService.insertObdPurchaseApplay(data);
		if (i > 0) {
			baseOutDTO.setErrorCode(Rescode.SUCCESS);
		} else {
			baseOutDTO.setErrorCode(Rescode.FAIL);
		}
		return baseOutDTO;
	}


	/**
	 * 更新采购为取消状态
	 *
	 * @return
	 */
	@RequestMapping(value = "/cancelApplayStatus")
	@ResponseBody
	public BaseOutDTO cancelApplayStatus(@RequestBody YsObdPurchaseApply data) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
//		int i = obdService.updatePurchaseApplyStatus(id, CommonEnum.AuditStatus.noNeed.getType(),YunStreamEnum.OBDPurchaseStatus.Closed.getType());
		data.setAuditStatus(CommonEnum.AuditStatus.noNeed.getType());
		data.setStatus(YunStreamEnum.OBDPurchaseStatus.Closed.getType());
		int i = obdService.updatePurchaseApplyStatus(data);
		if (i > 0) {
			baseOutDTO.setErrorCode(Rescode.SUCCESS);
		} else {
			baseOutDTO.setErrorCode(Rescode.FAIL);
		}
		return baseOutDTO;
	}

	/**
	 * 更新采购审核拒绝
	 *
	 * @return
	 */
	@RequestMapping(value = "/AuditApplayStatus")
	@ResponseBody
	public BaseOutDTO AuditApplayStatus(@RequestBody YsObdPurchaseApply data) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
//		int i = obdService.updatePurchaseApplyStatus(id, CommonEnum.AuditStatus.Refuse.getType(), YunStreamEnum.OBDPurchaseStatus.AuditRefuse.getType());
		data.setAuditStatus(CommonEnum.AuditStatus.Refuse.getType());
		data.setStatus(YunStreamEnum.OBDPurchaseStatus.AuditRefuse.getType());
		int i = obdService.updatePurchaseApplyStatus(data);
		if (i > 0) {
			baseOutDTO.setErrorCode(Rescode.SUCCESS);
		} else {
			baseOutDTO.setErrorCode(Rescode.FAIL);
		}
		return baseOutDTO;
	}

	/**
	 * 更新采购完成
	 *
	 * @return
	 */
	@RequestMapping(value = "/ObdApplyCompleteStatus")
	@ResponseBody
	public BaseOutDTO ObdApplyCompleteStatus(@RequestBody YsObdPurchaseApply data) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		data.setStatus(YunStreamEnum.OBDPurchaseStatus.Dealed.getType());
		int i = obdService.updatePurchaseApplyStatus(data);
		if (i > 0) {
			baseOutDTO.setErrorCode(Rescode.SUCCESS);
		} else {
			baseOutDTO.setErrorCode(Rescode.FAIL);
		}
		return baseOutDTO;
	}

	@RequestMapping(value="/addLogistics")
	@ResponseBody
	public ObdPurchaseApplyOutDTO  getObdPurchaseParamSettingByGroupId(@RequestBody YsObdPurchaseApply ysObdPurchaseApply){
		ObdPurchaseApplyOutDTO obdPurchaseApplyOutDTO=new ObdPurchaseApplyOutDTO();
		try {
			obdPurchaseApplyOutDTO = obdService.getObdLogisticsById(ysObdPurchaseApply);
			obdPurchaseApplyOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdPurchaseApplyOutDTO;
		} catch (ApplicationException ae) {
			obdPurchaseApplyOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdPurchaseApplyOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdPurchaseApplyOutDTO;
	}

	/**
	 * 更新采购审核拒绝
	 *
	 * @return
	 */
	@RequestMapping(value = "/CommitLogistics")
	@ResponseBody
	public BaseOutDTO CommitLogistics(@RequestBody YsObdPurchaseApply data) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		int i = obdService.updateLogistics(data);
		if (i > 0) {
			baseOutDTO.setErrorCode(Rescode.SUCCESS);
		} else {
			baseOutDTO.setErrorCode(Rescode.FAIL);
		}
		return baseOutDTO;
	}

	@RequestMapping(value="/getObdPurchaseParamSettingByGroupId")
	@ResponseBody
	public YsObdPurchaseSetOutDTO  getObdPurchaseParamSettingByGroupId(@RequestBody YsObdPurchaseSet ysObdPurchaseSet){
		YsObdPurchaseSetOutDTO ysObdPurchaseSetOutDTO=new YsObdPurchaseSetOutDTO();
		try {
			ysObdPurchaseSetOutDTO = obdService.getObdPurchaseParamSettingByGroupId(ysObdPurchaseSet);
			ysObdPurchaseSetOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return ysObdPurchaseSetOutDTO;
		} catch (ApplicationException ae) {
			ysObdPurchaseSetOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			ysObdPurchaseSetOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return ysObdPurchaseSetOutDTO;
	}

	@RequestMapping(value="/saveObdPurchaseParamSetting")
	@ResponseBody
	public BaseOutDTO  saveObdPurchaseParamSetting(@RequestBody YsObdPurchaseSet ysObdPurchaseSet){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {
			baseOutDTO = obdService.saveObdPurchaseParamSetting(ysObdPurchaseSet);
			baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return baseOutDTO;
	}

	/**
	 * 更换OBD设备
	 * @param
	 * @return
	 */
	@RequestMapping(value="/change")
	@ResponseBody
	public Boolean change(){
		Boolean result = false;
		Map map = new HashMap();
		map.put("id", getRequest().getParameter("id"));
		map.put("obdid", getRequest().getParameter("obdid"));
		map.put("simid", getRequest().getParameter("simid"));
		map.put("old_device_id", getRequest().getParameter("old_device_id"));
		map.put("old_sim_no", getRequest().getParameter("old_sim_no"));
		map.put("changereason", getRequest().getParameter("changereason"));
		try {
			YsObd obd = obdService.selectObdByDeviceId(getRequest().getParameter("obdid"));
			//更新旧OBD的状态
			int res = obdService.changeOBD(map);
			if(res != 0) {
				obdService.insertObdChange(map);
			}
			map.put("id", obd.getId()+"");
			//更改新OBD的状态和归属
			obdService.updateOBDByDevice(map);
			result = true;
		} catch (Exception e) {
			result = null;
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 判断该设备是否属于该用户并处于库存状态
	 * @return
	 */
	@RequestMapping(value="/checkObd")
	@ResponseBody
	public Boolean checkObd(){
		Boolean result = false;
		Map map = new HashMap();
		map.put("groupid", getRequest().getParameter("groupid"));
		map.put("obdid", getRequest().getParameter("obdid"));
		if(getRequest().getParameter("shopid") != null) {
			map.put("shopid", getRequest().getParameter("shopid"));
		}
		if(getRequest().getParameter("agentid") != null) {
			map.put("agentid", getRequest().getParameter("agentid"));
		}
		try {
			Integer id = obdService.selectOwnObdByDeviceid(map);
			if(id != null) {
				result = true;
			} else {
				result = false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e);
			result = false;
		}
		return result;
	}

	@RequestMapping(value="/cancelList")
	@ResponseBody
	public ObdStoreListOutDTO  cancelList(@RequestBody ObdInDTO obdInDTO){
		ObdStoreListOutDTO obdStoreListOutDTO=new ObdStoreListOutDTO();
		try {
			obdStoreListOutDTO = obdService.getCancelList(obdInDTO);
			obdStoreListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdStoreListOutDTO;
		} catch (ApplicationException ae) {
			obdStoreListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		catch (Exception e) {
			obdStoreListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdStoreListOutDTO;
	}

	@RequestMapping(value="/validobd")
	@ResponseBody
	public ObdStoreListOutDTO  validobd(@RequestBody Map param){
		ObdStoreListOutDTO obdStoreListOutDTO=new ObdStoreListOutDTO();
		try {
			int result = obdService.updateOBDValid(param);
			obdStoreListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return obdStoreListOutDTO;
		}
		catch (Exception e) {
			obdStoreListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return obdStoreListOutDTO;
	}
}
